/***********************************************************************
 *            Project: CoreCms
 *        ProjectName: 核心内容管理系统                                
 *                Web: https://www.corecms.net                      
 *             Author: 大灰灰                                          
 *              Email: jianweie@163.com                                
 *         CreateTime: 2021/1/31 21:45:10
 *        Description: 暂无
 ***********************************************************************/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using System.Web;
using Castle.Components.DictionaryAdapter.Xml;
using CoreCms.Net.Auth.HttpContextUser;
using CoreCms.Net.Configuration;
using CoreCms.Net.DTO;
using CoreCms.Net.Filter;
using CoreCms.Net.IRepository;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.Entities.Expression;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Model.ViewModels.Advertisement;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Services;
using CoreCms.Net.Utility.Extensions;
using CoreCms.Net.Utility.Helper;
using CoreCms.Net.Web.Admin.Infrastructure;
using Hangfire.Storage;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.HSSF.UserModel;
using NPOI.OpenXmlFormats.Dml.Chart;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using SqlSugar;

namespace CoreCms.Net.Web.Admin.Controllers
{
    /// <summary>
    ///     用户表
    /// </summary>
    [Description("用户表")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    [RequiredErrorForAdmin]
    [Authorize(Permissions.Name)]
    public class CoreCmsUserController : ControllerBase
    {
        private readonly ICoreCmsUserBalanceServices _coreCmsUserBalanceServices;
        private readonly ICoreCmsUserGradeServices _coreCmsUserGradeServices;
        private readonly ICoreCmsUserPointLogServices _coreCmsUserPointLogServices;
        private readonly ICoreCmsUserServices _coreCmsUserServices;
        private readonly IWebHostEnvironment _webHostEnvironment;
        private readonly ICoreCmsSourceServices _coreCmsSourceServices;
        private readonly ICoreCmsCustomerClassServices _coreCmsCustomerClassServices;
        private readonly ICoreCmsOrderTypeServices _coreCmsOrderTypeServices;
        private readonly ICoreCmsWechatnumberServices _coreCmsWechatnumberServices;
        private readonly ICoreCmsCustomerGroupServices _coreCmsCustomerGroupServices;
        private readonly ISysUserServices _sysUserServices;
        private readonly IHttpContextUser _user;
        private readonly ICoreCmsCompanyServices _coreCmsCompanyServices;
        private readonly ICoreCmsDepartmentServices _coreCmsDepartmentServices;
        private readonly ICoreCmsGroupServices _coreCmsGroupServices;
        private readonly ICoreCmsOrderLogServices _coreCmsOrderLogServices;
      //  private readonly ICoreCmsOrderTypeServices 

        /// <summary>
        ///     构造函数
        /// </summary>
        /// <param name="webHostEnvironment"></param>
        /// <param name="coreCmsUserServices"></param>
        /// <param name="coreCmsUserGradeServices"></param>
        /// <param name="coreCmsUserBalanceServices"></param>
        /// <param name="coreCmsUserPointLogServices"></param>
        /// <param name="coreCmsCustomerClassServices"></param>
        /// <param name="coreCmsSourceServices"></param>
        /// <param name="coreCmsOrderTypeServices"></param>
        /// <param name="coreCmsWechatnumberServices"></param>
        /// <param name="coreCmsCustomerGroupServices"></param>
        /// <param name="sysUserServices"></param>
        /// <param name="user"></param>
        /// <param name="coreCmsCompanyServices"></param>
        ///  <param name="coreCmsGroupServices"></param>
        ///  <param name="coreCmsDepartmentServices"></param>
        public CoreCmsUserController(
            IWebHostEnvironment webHostEnvironment
            , ICoreCmsUserServices coreCmsUserServices
            , ICoreCmsUserGradeServices coreCmsUserGradeServices
            , ICoreCmsUserBalanceServices coreCmsUserBalanceServices
            , ICoreCmsUserPointLogServices coreCmsUserPointLogServices
            ,ICoreCmsCustomerClassServices coreCmsCustomerClassServices
            ,ICoreCmsSourceServices coreCmsSourceServices
            ,ICoreCmsOrderTypeServices coreCmsOrderTypeServices
            ,ICoreCmsWechatnumberServices coreCmsWechatnumberServices
            ,ICoreCmsCustomerGroupServices coreCmsCustomerGroupServices
            ,ISysUserServices sysUserServices
            ,IHttpContextUser user
            ,ICoreCmsCompanyServices coreCmsCompanyServices
            ,ICoreCmsGroupServices coreCmsGroupServices,
            ICoreCmsDepartmentServices coreCmsDepartmentServices
            ,ICoreCmsOrderLogServices coreCmsOrderLogServices
        )
        {
            _webHostEnvironment = webHostEnvironment;
            _coreCmsUserServices = coreCmsUserServices;
            _coreCmsUserGradeServices = coreCmsUserGradeServices;
            _coreCmsUserBalanceServices = coreCmsUserBalanceServices;
            _coreCmsUserPointLogServices = coreCmsUserPointLogServices;
            _coreCmsCustomerClassServices = coreCmsCustomerClassServices;
            _coreCmsSourceServices = coreCmsSourceServices;
            _coreCmsOrderTypeServices = coreCmsOrderTypeServices;
            _coreCmsWechatnumberServices = coreCmsWechatnumberServices;
            _coreCmsCustomerGroupServices = coreCmsCustomerGroupServices;
            _sysUserServices = sysUserServices;
            _user = user;
            _coreCmsCompanyServices = coreCmsCompanyServices;
            _coreCmsDepartmentServices = coreCmsDepartmentServices;
            _coreCmsGroupServices = coreCmsGroupServices;
            _coreCmsOrderLogServices= coreCmsOrderLogServices;
        }

        #region 获取列表============================================================

        // POST: Api/CoreCmsUser/GetPageList
        /// <summary>
        ///     获取列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("获取列表")]
        public async Task<AdminUiCallBack> GetPageList()
        {
            var jm = new AdminUiCallBack();
            var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
            var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
            var where = PredicateBuilder.True<CoreCmsUser>();
            var roleName = _user.roleName;//角色
            //获取排序字段
            var orderField = Request.Form["orderField"].FirstOrDefault();

            Expression<Func<CoreCmsUser, object>> orderEx = orderField switch
            {
                "id" => p => p.id,
                "userName" => p => p.userName,
                "passWord" => p => p.passWord,
                "mobile" => p => p.mobile,
                "sex" => p => p.sex,
                "birthday" => p => p.birthday,
                "avatarImage" => p => p.avatarImage,
                "nickName" => p => p.nickName,
                "balance" => p => p.balance,
                "point" => p => p.point,
                "grade" => p => p.grade,
                "createTime" => p => p.createTime,
                "updataTime" => p => p.updataTime,
                "status" => p => p.status,
                "parentId" => p => p.parentId,
                "userWx" => p => p.userWx,
                "isDelete" => p => p.isDelete,
                "phone" => p => p.phone,
                "address" => p => p.address,
                "number" => p => p.number,
                "sourceId" => p => p.sourceId,
                "customerClassId" => p => p.customerClassId,
                "wechatnumberId" => p => p.wechatnumberId,
                "remarks" => p => p.remarks,
                "customerWx" => p => p.customerWx,
                "customerGroupId" => p => p.customerGroupId,
                "orderTypeId" => p => p.orderTypeId,
                _ => p => p.id
            };
            if (roleName.Contains("总经理"))
            {
                where = where.And(p => p.companyId == _user.companyId);
            }
            if (roleName=="经理"||roleName=="销售经理")
            {
                var departmentId1=_user.departmentId;
                where = where.And(p =>p.departmentId== departmentId1);
            }
            if (roleName == "组长"||roleName=="销售主管")
            {
                var _groupId = _user.groupId;
                where = where.And(p => p.groupId ==Convert.ToInt32(_user.groupId));
            }
            if (roleName == "组员")
            {
                //var groupId1 = _user.groupId;
                where = where.And(p => p.sysid == Convert.ToInt32(_user.userId));
            }
            //设置排序方式
            var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
            var orderBy = orderDirection switch
            {
                "asc" => OrderByType.Asc,
                "desc" => OrderByType.Desc,
                _ => OrderByType.Desc
            };
            //查询筛选
            var number = Request.Form["number"].FirstOrDefault();
            if (!string.IsNullOrEmpty(number))
            {
                where = where.And(p => p.number.Contains(number));
            }
            var userName = Request.Form["userName"].FirstOrDefault();
            if (!string.IsNullOrEmpty(userName))
            {
                where = where.And(p => p.userName.Contains(userName)) ;
            }
            var mobile = Request.Form["mobile"].FirstOrDefault();
            if (!string.IsNullOrEmpty(mobile))
            {
                where = where.And(p => p.mobile.Contains(mobile));
            }
            var status = Request.Form["status"].FirstOrDefault().ObjectToInt(0);
            if (status>0)
            {
                ////创建时间 datetime
                var createTime = Request.Form["createTime"].FirstOrDefault();

                if (status==6)//创建时间
                {

                    if (!string.IsNullOrEmpty(createTime))
                    {
                        if (createTime.Contains("到"))
                        {
                            var dts = createTime.Split("到");
                            var dtStart = dts[0].Trim().ObjectToDate();
                            where = where.And(p => p.createTime > dtStart);
                            var dtEnd = dts[1].Trim().ObjectToDate();
                            where = where.And(p => p.createTime < dtEnd);
                        }
                        else
                        {
                            var dt = createTime.ObjectToDate();
                            where = where.And(p => p.createTime > dt);
                        }
                    }
                }
               else if (status == 1)//新单分配时间
                {

                    if (!string.IsNullOrEmpty(createTime))
                    {
                        if (createTime.Contains("到"))
                        {
                            var dts = createTime.Split("到");
                            var dtStart = dts[0].Trim().ObjectToDate();
                            where = where.And(p => p.oneDivideTime > dtStart);
                            var dtEnd = dts[1].Trim().ObjectToDate();
                            where = where.And(p => p.oneDivideTime < dtEnd);
                        }
                        else
                        {
                            var dt = createTime.ObjectToDate();
                            where = where.And(p => p.oneDivideTime > dt);
                        }
                    }
                }
                else if (status == 2)//其他分配时间
                {

                    if (!string.IsNullOrEmpty(createTime))
                    {
                        if (createTime.Contains("到"))
                        {
                            var dts = createTime.Split("到");
                            var dtStart = dts[0].Trim().ObjectToDate();
                            where = where.And(p => p.otherDivideTime > dtStart);
                            var dtEnd = dts[1].Trim().ObjectToDate();
                            where = where.And(p => p.otherDivideTime < dtEnd);
                        }
                        else
                        {
                            var dt = createTime.ObjectToDate();
                            where = where.And(p => p.otherDivideTime > dt);
                        }
                    }
                }
                else if (status == 3)//下单时间
                {

                    if (!string.IsNullOrEmpty(createTime))
                    {
                        if (createTime.Contains("到"))
                        {
                            var dts = createTime.Split("到");
                            var dtStart = dts[0].Trim().ObjectToDate();
                            where = where.And(p => p.orderDivideTime > dtStart);
                            var dtEnd = dts[1].Trim().ObjectToDate();
                            where = where.And(p => p.orderDivideTime < dtEnd);
                        }
                        else
                        {
                            var dt = createTime.ObjectToDate();
                            where = where.And(p => p.orderDivideTime > dt);
                        }
                    }
                }
                else if (status == 4)//跟进时间
                {

                    if (!string.IsNullOrEmpty(createTime))
                    {
                        if (createTime.Contains("到"))
                        {
                            var dts = createTime.Split("到");
                            var dtStart = dts[0].Trim().ObjectToDate();
                            where = where.And(p => p.followDivideTiem > dtStart);
                            var dtEnd = dts[1].Trim().ObjectToDate();
                            where = where.And(p => p.followDivideTiem < dtEnd);
                        }
                        else
                        {
                            var dt = createTime.ObjectToDate();
                            where = where.And(p => p.followDivideTiem > dt);
                        }
                    }
                }
                else if (status == 5)//签收时间
                {

                    if (!string.IsNullOrEmpty(createTime))
                    {
                        if (createTime.Contains("到"))
                        {
                            var dts = createTime.Split("到");
                            var dtStart = dts[0].Trim().ObjectToDate();
                            where = where.And(p => p.signforDivideTime > dtStart);
                            var dtEnd = dts[1].Trim().ObjectToDate();
                            where = where.And(p => p.signforDivideTime < dtEnd);
                        }
                        else
                        {
                            var dt = createTime.ObjectToDate();
                            where = where.And(p => p.signforDivideTime > dt);
                        }
                    }
                }
                else if (status == 7)//加粉时间
                {

                    if (!string.IsNullOrEmpty(createTime))
                    {
                        if (createTime.Contains("到"))
                        {
                            var dts = createTime.Split("到");
                            var dtStart = dts[0].Trim().ObjectToDate();
                            where = where.And(p => p.addingDivideTime > dtStart);
                            var dtEnd = dts[1].Trim().ObjectToDate();
                            where = where.And(p => p.addingDivideTime < dtEnd);
                        }
                        else
                        {
                            var dt = createTime.ObjectToDate();
                            where = where.And(p => p.addingDivideTime > dt);
                        }
                    }
                }
            }
            //公司ID int
            var companyId = Request.Form["companyId"].FirstOrDefault().ObjectToInt(0);
            if (companyId > 0)
            {
                where = where.And(p => p.companyId == companyId);
            }
            //部门ID int
            var departmentId = Request.Form["departmentId"].FirstOrDefault().ObjectToInt(0);
            if (departmentId > 0)
            {
                where = where.And(p => p.departmentId == departmentId);
            }
            //组别ID int
            var groupId = Request.Form["groupId"].FirstOrDefault().ObjectToInt(0);
            if (groupId > 0)
            {
                where = where.And(p => p.groupId == groupId);
            }
            //来源 int
            var sourceId = Request.Form["sourceId"].FirstOrDefault().ObjectToInt(0);
            if (sourceId > 0)
            {
                where = where.And(p => p.sourceId == sourceId);
            }
            //客户分类 int
            var customerClassId = Request.Form["customerClassId"].FirstOrDefault().ObjectToInt(0);
            if (customerClassId > 0)
            {
                where = where.And(p => p.customerClassId == customerClassId);
            }
            //客户群组 int
            var customerGroupId = Request.Form["customerGroupId"].FirstOrDefault().ObjectToInt(0);
            if (customerGroupId > 0)
            {
                where = where.And(p => p.customerGroupId == customerGroupId);
            }
            //获取数据
            var list = await _coreCmsUserServices.QueryPageAsyncNew(where, orderEx, orderBy, pageCurrent, pageSize, true);
            //返回数据
            jm.data =list;
            jm.code = 0;
            jm.count = list.TotalCount;
            jm.msg = "数据调用成功!";
            return jm;
        }

        #endregion
        #region 用户数据上传============================================================
        /// <summary>
        /// 上传用户数据提交累
        /// </summary>
        public class FMInputUserInfo
        {
            public string url { get; set; }
            public string file { get; set; }


        }
        [HttpGet]
        public async Task<string> GetAsync()
        {


 
  
            // 接口请求结束
            return null;
        }

        public long getTimeSpan()
        {
            // 获取当前时间
            DateTimeOffset now = DateTimeOffset.UtcNow;

            // 转换为Unix时间戳（秒数）
            long unixTimestamp = now.ToUnixTimeSeconds();
            return unixTimestamp;
        }

        public async Task<string> GetContent(string url)
        {
            // 创建 HttpClient 实例
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    // 发送 GET 请求
                    HttpResponseMessage response = await client.GetAsync(url);

                    // 确保请求成功
                    //response.EnsureSuccessStatusCode();

                    // 读取响应内容
                    string responseBody = await response.Content.ReadAsStringAsync();

                    // 输出响应内容  
                    return $" 请求参数: {url} \n 请求结果数据: {responseBody}";
                }
                catch (HttpRequestException e)
                {
                    return $"请求参数: {url} \n 请求异常: {e.Message}";
                }
            }
        }
        /// <summary>
        /// 转资料
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("转资料")]
        public async Task<AdminUiCallBack> ChangeUser([FromBody] FMArrayIntIds entity)
        {

            var helper = new SignHelper();

            var parameters = new Dictionary<string, string>
            {
                { "method","trade.order.list"},
                { "app_id","1022215295"}, // 配置文件
                { "timestamp",getTimeSpan().ToString()},
                {"create_time_start","20250301000000"},
                {"create_time_end","20250301235959"},
                //{"update_time_start",""},
                //{"update_time_end",""},
                //{"status",""},
                //{"have_after_sale",""},
                {"next_id","0"},
                {"limit","200"}
            };
            var secret = "BIZTP4I49K8NEO0729HUT5PORZI9BH1E"; // 配置文件

            // 生成签名
            var sign = helper.GetSign(parameters, secret);
            Console.WriteLine($"Generated Sign: {sign}");

            // 测试验签
            var content = $"sign={sign}&{string.Join("&", parameters.Select(item => $"{item.Key}={HttpUtility.UrlEncode(item.Value)}").ToList())}";

            // 设置请求的 URL
            string url = "https://openapi.heliang.cc/gateway/v1/erp?" + content;
            var responseBody = await GetContent(url);
            //  OrderData dataservice = new OrderData();
            var number = responseBody.IndexOf("{");
            string jsonPart = responseBody.Substring(number).ToString();
          //  JObject jsonObj = JObject.Parse(strsjon);
          //  string jsonPart = responseBody.Split("\r\n")[1].Trim().Replace("请求结果数据: ", "");
            //Console.WriteLine(jsonPart); // 输出提取的 JSON 字符串进行检查
            var options = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            };

            //var apiResponse = JsonSerializer.Deserialize<ApiResponse>(json, options);
            var apiResponse =System.Text.Json.JsonSerializer.Deserialize<ApiResponse>(jsonPart, options);
            if (apiResponse != null)
            {
                Console.WriteLine($"Code: {apiResponse.Code}");
                Console.WriteLine($"Message: {apiResponse.Message}");
                if (apiResponse.Data != null && apiResponse.Data.List != null)
                {
                    foreach (var order in apiResponse.Data.List)
                    {
                        Console.WriteLine($"OutTradeNo: {order.out_trade_no}");
                    }
                }
            }
            string ddd = "";
            // var apiResponse =System.Text.Json.JsonSerializer.Deserialize<ApiResponse>(json.Split("\r\n")[1].Trim().Replace("请求结果数据: ", ""));
            //  var listOrder = await dataservice.ParseJsonAsync(strsjon);
            //var insertData = apiResponse.Select(order => new
            //{
            //    order.OutTradeNo,
            //    order.Status,
            //    order.PayStatus,
            //    order.CreateTime,
            //    order.PayTime,
            //    order.CompleteTime,
            //    order.PaymentFee,
            //    order.RefundFee,
            //    order.PayType,
            //    order.CouponFee,
            //    order.ExpressFee,
            //    order.TransactionNo,
            //    order.UpdateTime,
            //    order.AfterSaleStatus,
            //    order.AdReturnStatus,
            //    Buyer = System.Text.Json.JsonSerializer.Serialize(order.Buyer), // 序列化 Buyer 对象
            //    Express = System.Text.Json.JsonSerializer.Serialize(order.Express), // 序列化 Express 对象
            //    Business = System.Text.Json.JsonSerializer.Serialize(order.Business), // 序列化 Business 对象
            //    Details = System.Text.Json.JsonSerializer.Serialize(order.Details) // 序列化 Details 数组
            //}).ToList();
            // var ddd = insertData;
            //JsonDocument doc = JsonDocument.Parse(strsjon);
            //JsonElement dataElement = doc.RootElement.GetProperty("data");
            //JsonElement listElement = dataElement.GetProperty("list");
            //foreach (JsonElement itemElement in listElement.EnumerateArray())
            //{
            //    // 获取买家信息
            //    JsonElement buyerElement = itemElement.GetProperty("buyer");
            //    string buyerName = buyerElement.GetProperty("name").GetString();
            //    string buyerPhone = buyerElement.GetProperty("phone").GetString();
            //    string buyerProvince = buyerElement.GetProperty("province").GetString();
            //    string buyerCity = buyerElement.GetProperty("city").GetString();
            //    string buyerArea = buyerElement.GetProperty("area").GetString();
            //    string buyerAddress = buyerElement.GetProperty("address").GetString();
            //    string buyerNote = buyerElement.GetProperty("note").GetString();
            //}
            //async Task<AdminUiCallBack> 
            var jm = new AdminUiCallBack();
            //  var listModel = await _coreCmsUserServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id, OrderByType.Asc);
            var list = await _coreCmsUserServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id, OrderByType.Asc);
            var bl = false;
            if (list.Count>0)
            {
                var orderLog = new List<CoreCmsOrderLog>();
                foreach (var item in list)
                {
                    if (entity.sysid==item.sysid)
                    {
                        jm.msg = "操作失败";
                        continue;
                    }

                     bl = await _coreCmsUserServices.UpdateAsync(p => new CoreCmsUser() { oneDivideTime = DateTime.Now, sysid=entity.sysid,orderTypeId=1 }, p => p.id == item.id);
                    if (bl==true)
                    {
                        var sLog = new CoreCmsOrderLog
                        {
                            userId = item.id,
                            orderId = string.Empty,
                            type = (int)GlobalEnumVars.OrderLogTypes.Change,
                            msg = "转新单",
                            data = JsonConvert.SerializeObject(item),
                            createTime = DateTime.Now,
                            userName = _user.nickName,
                            number = item.number
                        };
                        orderLog.Add(sLog);
                    }

                }
                if (bl==true)
                {
                    await _coreCmsOrderLogServices.InsertAsync(orderLog);
                    jm.code = 0;
                }
              
                //订单记录

                //var orderLog = new CoreCmsOrderLog
                //{
                //    userId = userId,
                //    orderId = order.orderId,
                //    type = (int)GlobalEnumVars.OrderLogTypes.LOG_TYPE_CREATE,
                //    msg = "订单创建",
                //    data = JsonConvert.SerializeObject(order),
                //    createTime = DateTime.Now,
                //    userName = _user.nickName,
                //    number = number
                //};
                //await _orderLogServices.InsertAsync(orderLog);

            }

            return jm;
        }


        /// <summary>
        /// 淘单资料
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("淘单资料")]
        public async Task<AdminUiCallBack> TaodanUser([FromBody] FMArrayIntIds entity)
        {
            //async Task<AdminUiCallBack>
            var jm = new AdminUiCallBack();
            //  var listModel = await _coreCmsUserServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id, OrderByType.Asc);
            var list = await _coreCmsUserServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id, OrderByType.Asc);
            var bl = false;
            if (list.Count > 0)
            {
                var orderLog = new List<CoreCmsOrderLog>();
                foreach (var item in list)
                {
                    if (entity.sysid == item.sysid)
                    {
                        jm.msg = "操作失败";
                        continue;
                    }

                    bl = await _coreCmsUserServices.UpdateAsync(p => new CoreCmsUser() { otherDivideTime = DateTime.Now, sysid = entity.sysid,orderTypeId=1003 }, p => p.id == item.id);
                    if (bl == true)
                    {
                        var sLog = new CoreCmsOrderLog
                        {
                            userId = item.id,
                            orderId = string.Empty,
                            type = (int)GlobalEnumVars.OrderLogTypes.Change,
                            msg = "转淘单",
                            data = JsonConvert.SerializeObject(item),
                            createTime = DateTime.Now,
                            userName = _user.nickName,
                            number = item.number
                        };
                        orderLog.Add(sLog);
                    }

                }
                if (bl == true)
                {
                    await _coreCmsOrderLogServices.InsertAsync(orderLog);
                    jm.code = 0;
                }

                //订单记录

                //var orderLog = new CoreCmsOrderLog
                //{
                //    userId = userId,
                //    orderId = order.orderId,
                //    type = (int)GlobalEnumVars.OrderLogTypes.LOG_TYPE_CREATE,
                //    msg = "订单创建",
                //    data = JsonConvert.SerializeObject(order),
                //    createTime = DateTime.Now,
                //    userName = _user.nickName,
                //    number = number
                //};
                //await _orderLogServices.InsertAsync(orderLog);

            }

            return jm;
        }
        /// <summary>
        /// 复购转资料
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("复购资料")]
        public async Task<AdminUiCallBack> RepurchaseUser([FromBody] FMArrayIntIds entity)
        {
            //async Task<AdminUiCallBack>
            var jm = new AdminUiCallBack();
            //  var listModel = await _coreCmsUserServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id, OrderByType.Asc);
            var list = await _coreCmsUserServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id, OrderByType.Asc);
            var bl = false;
            if (list.Count > 0)
            {
                var orderLog = new List<CoreCmsOrderLog>();
                foreach (var item in list)
                {
                    if (entity.sysid == item.sysid)
                    {
                        jm.msg = "操作失败";
                        continue;
                    }

                    bl = await _coreCmsUserServices.UpdateAsync(p => new CoreCmsUser() { otherDivideTime = DateTime.Now, sysid = entity.sysid,orderTypeId=1003 }, p => p.id == item.id);
                    if (bl == true)
                    {
                        var sLog = new CoreCmsOrderLog
                        {
                            userId = item.id,
                            orderId = string.Empty,
                            type = (int)GlobalEnumVars.OrderLogTypes.Change,
                            msg = "转复购",
                            data = JsonConvert.SerializeObject(item),
                            createTime = DateTime.Now,
                            userName = _user.nickName,
                            number = item.number
                        };
                        orderLog.Add(sLog);
                    }

                }
                if (bl == true)
                {
                    await _coreCmsOrderLogServices.InsertAsync(orderLog);
                    jm.code = 0;
                }

                //订单记录

                //var orderLog = new CoreCmsOrderLog
                //{
                //    userId = userId,
                //    orderId = order.orderId,
                //    type = (int)GlobalEnumVars.OrderLogTypes.LOG_TYPE_CREATE,
                //    msg = "订单创建",
                //    data = JsonConvert.SerializeObject(order),
                //    createTime = DateTime.Now,
                //    userName = _user.nickName,
                //    number = number
                //};
                //await _orderLogServices.InsertAsync(orderLog);

            }

            return jm;
        }

        // POST: Api/CoreCmsUser/DoSetisDelete/10
        /// <summary>
        /// 导入客户资料
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("导入客户资料")]
        public AdminUiCallBack DoUploadUserInfos([FromBody] FMInputUserInfo entity)
        {
            var jm = new AdminUiCallBack();

            var users = new List<CoreCmsUser>();

            var dirPath = _webHostEnvironment.WebRootPath + entity.url;
            NPOIMemoryStream stream = new NPOIMemoryStream();
            using (FileStream file = new FileStream(dirPath, FileMode.Open, FileAccess.ReadWrite))
            {
                file.CopyTo(stream);
                stream.Position = 0;

                IWorkbook workbook = null;
                if (dirPath.ToLower().Contains(".xlsx"))
                {
                    workbook = new XSSFWorkbook(stream);
                }
                else
                {
                    workbook = new HSSFWorkbook(stream);
                }
                ISheet sheet = workbook.GetSheetAt(0);

                // 从第二行开始读取数据，第一行为表头
                for (int rowIndex = 1; rowIndex <= sheet.LastRowNum; rowIndex++)
                {
                    IRow row = sheet.GetRow(rowIndex);
                    if (row != null)
                    {
                        string name = row.GetCell(0)?.ToString() ?? "";
                        int age = int.TryParse(row.GetCell(1)?.ToString(), out int parsedAge) ? parsedAge : 0;

                        users.Add(new CoreCmsUser { nickName = name, id = age });

                    }
                }
            }

            jm.data = users;


            return jm;
        }

        #endregion
        //public class NPOIMemoryStream : MemoryStream
        //{
        //    /// <summary>
        //    /// 获取流是否关闭
        //    /// </summary>
        //    public bool IsColse
        //    {
        //        get;
        //        private set;
        //    }
        //    public NPOIMemoryStream(bool colse = false)
        //    {
        //        IsColse = colse;
        //    }
        //    public override void Close()
        //    {
        //        if (IsColse)
        //        {
        //            base.Close();
        //        }
        //    }
        //}

        #region 首页数据============================================================
        // POST: Api/CoreCmsOrder/AddGetIndex
        /// <summary>
        /// 跟进客查询户编号
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("跟进客查询户编号")]
        public async Task<AdminUiCallBack> AddGetIndex([FromBody] FMIntId entity)
        {
            //返回数据
            var jm = new AdminUiCallBack { code = 0 };
            return jm;
        }
        #endregion

        #region 首页数据============================================================

        // POST: Api/CoreCmsUser/GetIndex
        /// <summary>
        ///     首页数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("首页数据")]
        public async Task<AdminUiCallBack> GetIndex()
        {
            //返回数据
            var jm = new AdminUiCallBack { code = 0 };

            var sexTypes = EnumHelper.EnumToList<GlobalEnumVars.UserSexTypes>();
            var userStatus = EnumHelper.EnumToList<GlobalEnumVars.UserStatus>();
            var userAccountTypes = EnumHelper.EnumToList<GlobalEnumVars.UserAccountTypes>();
            var timeList= EnumHelper.EnumToList<GlobalEnumVars.DivideList>();
            var userGrade = await _coreCmsUserGradeServices.QueryAsync();
            var sourceList = await _coreCmsSourceServices.QueryAsync();
            var customerClassList=await _coreCmsCustomerClassServices.QueryAsync();
            var customerGroupList = await _coreCmsCustomerGroupServices.QueryAsync();
            string roleName = _user.roleName;
            var companyId = _user.companyId;
            var departmentId=_user.departmentId;
            var groupId=_user.groupId;
            var companyList1 = await _coreCmsCompanyServices.QueryAsync();
           var  departmentList1=await _coreCmsDepartmentServices.QueryAsync();
            var groupList1=await _coreCmsGroupServices.QueryAsync();
            List<CoreCmsCompany> companyList = new List<CoreCmsCompany>();
            List<CoreCmsDepartment> departmentList = new List<CoreCmsDepartment>();
            List<CoreCmsGroup> groupList = new List<CoreCmsGroup>();
            var orderTypeList = await _coreCmsOrderTypeServices.QueryAsync();

            //CoreCmsCompany companyList = new CoreCmsCompany();
            if (roleName=="销售经理")
            {
                departmentList = await _coreCmsDepartmentServices.QueryListByClauseAsync(p => p.companyid ==_user.companyId);
               
            }
            if (roleName == "销售主管")
            {
                groupList = await _coreCmsGroupServices.QueryListByClauseAsync(p => p.dId == _user.departmentId);
                
            }
            if (roleName == "总经理")
            {
                companyList = await _coreCmsCompanyServices.QueryListByClauseAsync(p => p.id == companyId);
            }
            if (roleName.Contains("管理")||roleName=="跟单"||roleName=="审单"||roleName=="仓库")
            {
                companyList = await _coreCmsCompanyServices.QueryAsync();
                //departmentList = await _coreCmsDepartmentServices.QueryAsync();
                //groupList = await _coreCmsGroupServices.QueryAsync();
            }
            if (roleName == "组长" || roleName == "组员")
            {
                //companyList = null;
                //departmentList = null;
                //groupList = null;
            }

            //订单状态说明
            var orderStatus = EnumHelper.EnumToList<GlobalEnumVars.OrderStatus>();
            //if (roleName=="经理")
            //{
            //    companyList= await _coreCmsCompanyServices.QueryListByClauseAsync(p=>p.id==companyId);
            //    departmentList = await _coreCmsDepartmentServices.QueryListByClauseAsync(p => p.companyid == companyId);
            //    groupList=await _coreCmsGroupServices.QueryListByClauseAsync(p=>p.dId==departmentId);
            //}
            var sysUserList = await _sysUserServices.QueryAsync();
           
            //var departmentList=await _corecmsd
            var userId = _user.userId;
            jm.data = new
            {
                sexTypes,
                userStatus,
                userGrade,
                userAccountTypes,
                sysUserList,
                userId,
                companyList,
                groupList,
                departmentList,
                sourceList,
                customerClassList,
                customerGroupList,
                timeList,
                orderStatus,
                orderTypeList,
                roleName,
                companyList1,
                groupList1,
                departmentList1
            };
            jm.roleName = roleName;
            return jm;
        }

        #endregion

        #region 创建数据============================================================

        // POST: Api/CoreCmsUser/GetCreate
        /// <summary>
        ///     创建数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("创建数据")]
        public async Task<AdminUiCallBack> GetCreate()
        {
            //返回数据
            var jm = new AdminUiCallBack { code = 0 };

           // var userGrade = await _coreCmsUserGradeServices.QueryAsync(false, true);
          
            var classList=await _coreCmsCustomerClassServices.QueryAsync();//客户分类
            var sourceList = await _coreCmsSourceServices.QueryAsync();//来源
            var  orderTypeList=await _coreCmsOrderTypeServices.QueryAsync();//订单类型
            var wxNumberList = await _coreCmsWechatnumberServices.QueryAsync();//归属微信号
            var customerGroupList=await _coreCmsCustomerGroupServices.QueryAsync();//群体
            var sysuserList = await _sysUserServices.QueryAsync();//归属销售
            var userId = _user.ID;
            jm.data =new { classList, sourceList,orderTypeList,wxNumberList,customerGroupList,sysuserList,userId };

            return jm;
        }

        #endregion

        #region 创建提交============================================================

        // POST: Api/CoreCmsUser/DoCreate
        /// <summary>
        ///     创建提交
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("创建提交")]
        public async Task<AdminUiCallBack> DoCreate([FromBody] CoreCmsUser entity)
        {
            var jm = new AdminUiCallBack();

            if (string.IsNullOrEmpty(entity.mobile))
            {
                jm.msg = "请输入用户手机号";
                return jm;
            }

            var isHava = await _coreCmsUserServices.ExistsAsync(p => p.mobile == entity.mobile);
            if (isHava)
            {
                jm.msg = "已存在此手机号码";
                return jm;
            }
            var sysModel = await _sysUserServices.QueryByClauseAsync(p=>p.id==entity.sysid);

            entity.createTime = DateTime.Now;
            //entity.passWord = CommonHelper.Md5For32(entity.passWord);
            entity.parentId = 0;
            entity.number = await _coreCmsUserServices.GetLastAccount();
            entity.departmentId=sysModel.departmentId;
            entity.companyId=sysModel.companyId;
            entity.groupId= sysModel.groupId;
            entity.addingDivideTime = entity.oneDivideTime;
            //entity.remarks= entity.remarks;
            var bl = await _coreCmsUserServices.InsertAsync(entity) > 0;
            jm.code = bl ? 0 : 1;
            jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;

            return jm;
        }

        #endregion

        #region 编辑数据============================================================

        // POST: Api/CoreCmsUser/GetEdit
        /// <summary>
        ///     编辑数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("编辑数据")]
        public async Task<AdminUiCallBack> GetEdit([FromBody] FMIntId entity)
        {
            var jm = new AdminUiCallBack();

            var model = await _coreCmsUserServices.QueryByIdAsync(entity.id);
            if (model == null)
            {
                jm.msg = "不存在此信息";
                return jm;
            }

            jm.code = 0;
            var classList = await _coreCmsCustomerClassServices.QueryAsync();//客户分类
            var sourceList = await _coreCmsSourceServices.QueryAsync();//来源
            var orderTypeList = await _coreCmsOrderTypeServices.QueryAsync();//订单类型
            var wxNumberList = await _coreCmsWechatnumberServices.QueryAsync();//归属微信号
            var customerGroupList = await _coreCmsCustomerGroupServices.QueryAsync();//群体
            var sexTypes = EnumHelper.EnumToList<GlobalEnumVars.UserSexTypes>();
            var userStatus = EnumHelper.EnumToList<GlobalEnumVars.UserStatus>();
            var sysUserList = await _sysUserServices.QueryAsync();//归属销售
           // var userGrade = await _coreCmsUserGradeServices.QueryAsync(false, true);

            jm.data = new
            {
                model,
                classList,
                sourceList,
                sexTypes,
                userStatus,
                orderTypeList,
                sysUserList
            };

            return jm;
        }

        #endregion

        #region 编辑提交============================================================

        // POST: Admins/CoreCmsUser/Edit
        /// <summary>
        ///     编辑提交
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("编辑提交")]
        public async Task<AdminUiCallBack> DoEdit([FromBody] CoreCmsUser entity)
        {
            var jm = new AdminUiCallBack();

            var oldModel = await _coreCmsUserServices.QueryByIdAsync(entity.id);
            if (oldModel == null)
            {
                jm.msg = "不存在此信息";
                return jm;
            }

            if (entity.mobile != oldModel.mobile)
            {
                var isHava = await _coreCmsUserServices.ExistsAsync(p => p.mobile == entity.mobile);
                if (isHava)
                {
                    jm.msg = "已存在此手机号码";
                    return jm;
                }
            }

            //事物处理过程开始
            if (!string.IsNullOrEmpty(entity.newaddress))
            {
                oldModel.address = entity.newaddress;
            }
            else
            {
                oldModel.address = entity.address;
            }

            if (!string.IsNullOrEmpty(entity.passWord)) oldModel.passWord = CommonHelper.Md5For32(entity.passWord);
            oldModel.mobile = entity.mobile;
            oldModel.sex = entity.sex;
            oldModel.birthday = entity.birthday;
            oldModel.avatarImage = entity.avatarImage;
            oldModel.nickName = entity.nickName;
            oldModel.grade = entity.grade;
            oldModel.updataTime = DateTime.Now;
            oldModel.status = entity.status;
            oldModel.sourceId=entity.sourceId;
            oldModel.customerClassId= entity.customerClassId;
            oldModel.phone = entity.phone;
            oldModel.customerWx=entity.customerWx;
            oldModel.orderTypeId = entity.orderTypeId;
            oldModel.sysid= entity.sysid;
            oldModel.remarks = entity.remarks;
            if (!string.IsNullOrEmpty(entity.newaddress))
            {
                oldModel.address=entity.newaddress.Replace(" ", "");
            }
            //事物处理过程结束
            var bl = await _coreCmsUserServices.UpdateAsync(oldModel);
            jm.code = bl ? 0 : 1;
            jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;

            return jm;
        }

        #endregion

        #region 选择导出============================================================
        // POST: Api/CoreCmsUser/SelectExportExcel/10
        /// <summary>
        /// 选择导出
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("选择导出")]
        public async Task<AdminUiCallBack> SelectExportExcel([FromBody] FMArrayIntIds entity)
        {
            var jm = new AdminUiCallBack();

            //创建Excel文件的对象
            var book = new HSSFWorkbook();
            //添加一个sheet
            var mySheet = book.CreateSheet("Sheet1");
            //获取list数据
            var listModel = await _coreCmsUserServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id, OrderByType.Asc);
            //给sheet1添加第一行的头部标题
            var headerRow = mySheet.CreateRow(0);
            var headerStyle = ExcelHelper.GetHeaderStyle(book);

            var cell0 = headerRow.CreateCell(0);
            cell0.SetCellValue("用户ID");
            cell0.CellStyle = headerStyle;
            mySheet.SetColumnWidth(0, 10 * 256);

            var cell1 = headerRow.CreateCell(1);
            cell1.SetCellValue("用户名");
            cell1.CellStyle = headerStyle;
            mySheet.SetColumnWidth(1, 10 * 256);

            var cell2 = headerRow.CreateCell(2);
            cell2.SetCellValue("密码");
            cell2.CellStyle = headerStyle;
            mySheet.SetColumnWidth(2, 10 * 256);

            var cell3 = headerRow.CreateCell(3);
            cell3.SetCellValue("手机号");
            cell3.CellStyle = headerStyle;
            mySheet.SetColumnWidth(3, 10 * 256);

            var cell4 = headerRow.CreateCell(4);
            cell4.SetCellValue("性别[1男2女3未知]");
            cell4.CellStyle = headerStyle;
            mySheet.SetColumnWidth(4, 10 * 256);

            var cell5 = headerRow.CreateCell(5);
            cell5.SetCellValue("生日");
            cell5.CellStyle = headerStyle;
            mySheet.SetColumnWidth(5, 10 * 256);

            var cell6 = headerRow.CreateCell(6);
            cell6.SetCellValue("头像");
            cell6.CellStyle = headerStyle;
            mySheet.SetColumnWidth(6, 10 * 256);

            var cell7 = headerRow.CreateCell(7);
            cell7.SetCellValue("昵称");
            cell7.CellStyle = headerStyle;
            mySheet.SetColumnWidth(7, 10 * 256);

            var cell8 = headerRow.CreateCell(8);
            cell8.SetCellValue("余额");
            cell8.CellStyle = headerStyle;
            mySheet.SetColumnWidth(8, 10 * 256);

            var cell9 = headerRow.CreateCell(9);
            cell9.SetCellValue("积分");
            cell9.CellStyle = headerStyle;
            mySheet.SetColumnWidth(9, 10 * 256);

            var cell10 = headerRow.CreateCell(10);
            cell10.SetCellValue("用户等级");
            cell10.CellStyle = headerStyle;
            mySheet.SetColumnWidth(10, 10 * 256);

            var cell11 = headerRow.CreateCell(11);
            cell11.SetCellValue("创建时间");
            cell11.CellStyle = headerStyle;
            mySheet.SetColumnWidth(11, 10 * 256);

            var cell12 = headerRow.CreateCell(12);
            cell12.SetCellValue("更新时间");
            cell12.CellStyle = headerStyle;
            mySheet.SetColumnWidth(12, 10 * 256);

            var cell13 = headerRow.CreateCell(13);
            cell13.SetCellValue("状态[1正常2停用]");
            cell13.CellStyle = headerStyle;
            mySheet.SetColumnWidth(13, 10 * 256);

            var cell14 = headerRow.CreateCell(14);
            cell14.SetCellValue("推荐人");
            cell14.CellStyle = headerStyle;
            mySheet.SetColumnWidth(14, 10 * 256);

            var cell15 = headerRow.CreateCell(15);
            cell15.SetCellValue("关联三方账户");
            cell15.CellStyle = headerStyle;
            mySheet.SetColumnWidth(15, 10 * 256);

            var cell16 = headerRow.CreateCell(16);
            cell16.SetCellValue("删除标志 有数据就是删除");
            cell16.CellStyle = headerStyle;
            mySheet.SetColumnWidth(16, 10 * 256);

            headerRow.Height = 30 * 20;
            var commonCellStyle = ExcelHelper.GetCommonStyle(book);

            //将数据逐步写入sheet1各个行
            for (var i = 0; i < listModel.Count; i++)
            {
                var rowTemp = mySheet.CreateRow(i + 1);

                var rowTemp0 = rowTemp.CreateCell(0);
                rowTemp0.SetCellValue(listModel[i].id.ToString());
                rowTemp0.CellStyle = commonCellStyle;

                var rowTemp1 = rowTemp.CreateCell(1);
                rowTemp1.SetCellValue(listModel[i].userName);
                rowTemp1.CellStyle = commonCellStyle;

                var rowTemp2 = rowTemp.CreateCell(2);
                rowTemp2.SetCellValue(listModel[i].passWord);
                rowTemp2.CellStyle = commonCellStyle;

                var rowTemp3 = rowTemp.CreateCell(3);
                rowTemp3.SetCellValue(listModel[i].mobile);
                rowTemp3.CellStyle = commonCellStyle;

                var rowTemp4 = rowTemp.CreateCell(4);
                rowTemp4.SetCellValue(listModel[i].sex.ToString());
                rowTemp4.CellStyle = commonCellStyle;

                var rowTemp5 = rowTemp.CreateCell(5);
                rowTemp5.SetCellValue(listModel[i].birthday.ToString());
                rowTemp5.CellStyle = commonCellStyle;

                var rowTemp6 = rowTemp.CreateCell(6);
                rowTemp6.SetCellValue(listModel[i].avatarImage);
                rowTemp6.CellStyle = commonCellStyle;

                var rowTemp7 = rowTemp.CreateCell(7);
                rowTemp7.SetCellValue(listModel[i].nickName);
                rowTemp7.CellStyle = commonCellStyle;

                var rowTemp8 = rowTemp.CreateCell(8);
                rowTemp8.SetCellValue(listModel[i].balance.ToString());
                rowTemp8.CellStyle = commonCellStyle;

                var rowTemp9 = rowTemp.CreateCell(9);
                rowTemp9.SetCellValue(listModel[i].point.ToString());
                rowTemp9.CellStyle = commonCellStyle;

                var rowTemp10 = rowTemp.CreateCell(10);
                rowTemp10.SetCellValue(listModel[i].grade.ToString());
                rowTemp10.CellStyle = commonCellStyle;

                var rowTemp11 = rowTemp.CreateCell(11);
                rowTemp11.SetCellValue(listModel[i].createTime.ToString());
                rowTemp11.CellStyle = commonCellStyle;

                var rowTemp12 = rowTemp.CreateCell(12);
                rowTemp12.SetCellValue(listModel[i].updataTime.ToString());
                rowTemp12.CellStyle = commonCellStyle;

                var rowTemp13 = rowTemp.CreateCell(13);
                rowTemp13.SetCellValue(listModel[i].status.ToString());
                rowTemp13.CellStyle = commonCellStyle;

                var rowTemp14 = rowTemp.CreateCell(14);
                rowTemp14.SetCellValue(listModel[i].parentId.ToString());
                rowTemp14.CellStyle = commonCellStyle;

                var rowTemp15 = rowTemp.CreateCell(15);
                rowTemp15.SetCellValue(listModel[i].userWx.ToString());
                rowTemp15.CellStyle = commonCellStyle;

                var rowTemp16 = rowTemp.CreateCell(16);
                rowTemp16.SetCellValue(listModel[i].isDelete.ToString());
                rowTemp16.CellStyle = commonCellStyle;

            }
            // 导出excel
            string webRootPath = _webHostEnvironment.WebRootPath;
            string tpath = "/files/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-CoreCmsUser导出(选择结果).xls";
            string filePath = webRootPath + tpath;
            DirectoryInfo di = new DirectoryInfo(filePath);
            if (!di.Exists)
            {
                di.Create();
            }
            FileStream fileHssf = new FileStream(filePath + fileName, FileMode.Create);
            book.Write(fileHssf);
            fileHssf.Close();

            jm.code = 0;
            jm.msg = GlobalConstVars.ExcelExportSuccess;
            jm.data = tpath + fileName;

            return jm;
        }
        #endregion

        #region 查询导出============================================================
        // POST: Api/CoreCmsUser/QueryExportExcel/10
        /// <summary>
        /// 查询导出
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("查询导出")]
        public async Task<AdminUiCallBack> QueryExportExcel()
        {
            var jm = new AdminUiCallBack();

            var where = PredicateBuilder.True<CoreCmsUser>();
            //查询筛选

            //用户ID int
            var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
            if (id > 0)
            {
                where = where.And(p => p.id == id);
            }
            //用户名 nvarchar
            var userName = Request.Form["userName"].FirstOrDefault();
            if (!string.IsNullOrEmpty(userName))
            {
                where = where.And(p => p.userName.Contains(userName));
            }
            //密码 nvarchar
            var passWord = Request.Form["passWord"].FirstOrDefault();
            if (!string.IsNullOrEmpty(passWord))
            {
                where = where.And(p => p.passWord.Contains(passWord));
            }
            //手机号 nvarchar
            var mobile = Request.Form["mobile"].FirstOrDefault();
            if (!string.IsNullOrEmpty(mobile))
            {
                where = where.And(p => p.mobile.Contains(mobile));
            }
            //性别[1男2女3未知] int
            var sex = Request.Form["sex"].FirstOrDefault().ObjectToInt(0);
            if (sex > 0)
            {
                where = where.And(p => p.sex == sex);
            }
            //头像 nvarchar
            var avatarImage = Request.Form["avatarImage"].FirstOrDefault();
            if (!string.IsNullOrEmpty(avatarImage))
            {
                where = where.And(p => p.avatarImage.Contains(avatarImage));
            }
            //昵称 nvarchar
            var nickName = Request.Form["nickName"].FirstOrDefault();
            if (!string.IsNullOrEmpty(nickName))
            {
                where = where.And(p => p.nickName.Contains(nickName));
            }
            //积分 int
            var point = Request.Form["point"].FirstOrDefault().ObjectToInt(0);
            if (point > 0)
            {
                where = where.And(p => p.point == point);
            }
            //用户等级 int
            var grade = Request.Form["grade"].FirstOrDefault().ObjectToInt(0);
            if (grade > 0)
            {
                where = where.And(p => p.grade == grade);
            }
            //创建时间 datetime
            var createTime = Request.Form["createTime"].FirstOrDefault();
            if (!string.IsNullOrEmpty(createTime))
            {
                var dt = createTime.ObjectToDate();
                where = where.And(p => p.createTime > dt);
            }
            //更新时间 datetime
            var updataTime = Request.Form["updataTime"].FirstOrDefault();
            if (!string.IsNullOrEmpty(updataTime))
            {
                var dt = updataTime.ObjectToDate();
                where = where.And(p => p.updataTime > dt);
            }
            //状态[1正常2停用] int
            var status = Request.Form["status"].FirstOrDefault().ObjectToInt(0);
            if (status > 0)
            {
                where = where.And(p => p.status == status);
            }
            //推荐人 int
            var parentId = Request.Form["parentId"].FirstOrDefault().ObjectToInt(0);
            if (parentId > 0)
            {
                where = where.And(p => p.parentId == parentId);
            }
            //关联三方账户 int
            var userWx = Request.Form["userWx"].FirstOrDefault().ObjectToInt(0);
            if (userWx > 0)
            {
                where = where.And(p => p.userWx == userWx);
            }
            //删除标志 有数据就是删除 bit
            var isDelete = Request.Form["isDelete"].FirstOrDefault();
            if (!string.IsNullOrEmpty(isDelete) && isDelete.ToLowerInvariant() == "true")
            {
                where = where.And(p => p.isDelete == true);
            }
            else if (!string.IsNullOrEmpty(isDelete) && isDelete.ToLowerInvariant() == "false")
            {
                where = where.And(p => p.isDelete == false);
            }
            //获取数据
            //创建Excel文件的对象
            var book = new HSSFWorkbook();
            //添加一个sheet
            var mySheet = book.CreateSheet("Sheet1");
            //获取list数据
            var listModel = await _coreCmsUserServices.QueryListByClauseAsync(where, p => p.id, OrderByType.Asc);
            //给sheet1添加第一行的头部标题
            var headerRow = mySheet.CreateRow(0);
            var headerStyle = ExcelHelper.GetHeaderStyle(book);

            var cell0 = headerRow.CreateCell(0);
            cell0.SetCellValue("用户ID");
            cell0.CellStyle = headerStyle;
            mySheet.SetColumnWidth(0, 10 * 256);

            var cell1 = headerRow.CreateCell(1);
            cell1.SetCellValue("用户名");
            cell1.CellStyle = headerStyle;
            mySheet.SetColumnWidth(1, 10 * 256);

            var cell2 = headerRow.CreateCell(2);
            cell2.SetCellValue("密码");
            cell2.CellStyle = headerStyle;
            mySheet.SetColumnWidth(2, 10 * 256);

            var cell3 = headerRow.CreateCell(3);
            cell3.SetCellValue("手机号");
            cell3.CellStyle = headerStyle;
            mySheet.SetColumnWidth(3, 10 * 256);

            var cell4 = headerRow.CreateCell(4);
            cell4.SetCellValue("性别[1男2女3未知]");
            cell4.CellStyle = headerStyle;
            mySheet.SetColumnWidth(4, 10 * 256);

            var cell5 = headerRow.CreateCell(5);
            cell5.SetCellValue("生日");
            cell5.CellStyle = headerStyle;
            mySheet.SetColumnWidth(5, 10 * 256);

            var cell6 = headerRow.CreateCell(6);
            cell6.SetCellValue("头像");
            cell6.CellStyle = headerStyle;
            mySheet.SetColumnWidth(6, 10 * 256);

            var cell7 = headerRow.CreateCell(7);
            cell7.SetCellValue("昵称");
            cell7.CellStyle = headerStyle;
            mySheet.SetColumnWidth(7, 10 * 256);

            var cell8 = headerRow.CreateCell(8);
            cell8.SetCellValue("余额");
            cell8.CellStyle = headerStyle;
            mySheet.SetColumnWidth(8, 10 * 256);

            var cell9 = headerRow.CreateCell(9);
            cell9.SetCellValue("积分");
            cell9.CellStyle = headerStyle;
            mySheet.SetColumnWidth(9, 10 * 256);

            var cell10 = headerRow.CreateCell(10);
            cell10.SetCellValue("用户等级");
            cell10.CellStyle = headerStyle;
            mySheet.SetColumnWidth(10, 10 * 256);

            var cell11 = headerRow.CreateCell(11);
            cell11.SetCellValue("创建时间");
            cell11.CellStyle = headerStyle;
            mySheet.SetColumnWidth(11, 10 * 256);

            var cell12 = headerRow.CreateCell(12);
            cell12.SetCellValue("更新时间");
            cell12.CellStyle = headerStyle;
            mySheet.SetColumnWidth(12, 10 * 256);

            var cell13 = headerRow.CreateCell(13);
            cell13.SetCellValue("状态[1正常2停用]");
            cell13.CellStyle = headerStyle;
            mySheet.SetColumnWidth(13, 10 * 256);

            var cell14 = headerRow.CreateCell(14);
            cell14.SetCellValue("推荐人");
            cell14.CellStyle = headerStyle;
            mySheet.SetColumnWidth(14, 10 * 256);

            var cell15 = headerRow.CreateCell(15);
            cell15.SetCellValue("关联三方账户");
            cell15.CellStyle = headerStyle;
            mySheet.SetColumnWidth(15, 10 * 256);

            var cell16 = headerRow.CreateCell(16);
            cell16.SetCellValue("删除标志 有数据就是删除");
            cell16.CellStyle = headerStyle;
            mySheet.SetColumnWidth(16, 10 * 256);


            headerRow.Height = 30 * 20;
            var commonCellStyle = ExcelHelper.GetCommonStyle(book);

            //将数据逐步写入sheet1各个行
            for (var i = 0; i < listModel.Count; i++)
            {
                var rowTemp = mySheet.CreateRow(i + 1);


                var rowTemp0 = rowTemp.CreateCell(0);
                rowTemp0.SetCellValue(listModel[i].id.ToString());
                rowTemp0.CellStyle = commonCellStyle;



                var rowTemp1 = rowTemp.CreateCell(1);
                rowTemp1.SetCellValue(listModel[i].userName);
                rowTemp1.CellStyle = commonCellStyle;



                var rowTemp2 = rowTemp.CreateCell(2);
                rowTemp2.SetCellValue(listModel[i].passWord);
                rowTemp2.CellStyle = commonCellStyle;



                var rowTemp3 = rowTemp.CreateCell(3);
                rowTemp3.SetCellValue(listModel[i].mobile);
                rowTemp3.CellStyle = commonCellStyle;



                var rowTemp4 = rowTemp.CreateCell(4);
                rowTemp4.SetCellValue(listModel[i].sex.ToString());
                rowTemp4.CellStyle = commonCellStyle;



                var rowTemp5 = rowTemp.CreateCell(5);
                rowTemp5.SetCellValue(listModel[i].birthday.ToString());
                rowTemp5.CellStyle = commonCellStyle;



                var rowTemp6 = rowTemp.CreateCell(6);
                rowTemp6.SetCellValue(listModel[i].avatarImage);
                rowTemp6.CellStyle = commonCellStyle;



                var rowTemp7 = rowTemp.CreateCell(7);
                rowTemp7.SetCellValue(listModel[i].nickName);
                rowTemp7.CellStyle = commonCellStyle;



                var rowTemp8 = rowTemp.CreateCell(8);
                rowTemp8.SetCellValue(listModel[i].balance.ToString());
                rowTemp8.CellStyle = commonCellStyle;



                var rowTemp9 = rowTemp.CreateCell(9);
                rowTemp9.SetCellValue(listModel[i].point.ToString());
                rowTemp9.CellStyle = commonCellStyle;



                var rowTemp10 = rowTemp.CreateCell(10);
                rowTemp10.SetCellValue(listModel[i].grade.ToString());
                rowTemp10.CellStyle = commonCellStyle;



                var rowTemp11 = rowTemp.CreateCell(11);
                rowTemp11.SetCellValue(listModel[i].createTime.ToString());
                rowTemp11.CellStyle = commonCellStyle;



                var rowTemp12 = rowTemp.CreateCell(12);
                rowTemp12.SetCellValue(listModel[i].updataTime.ToString());
                rowTemp12.CellStyle = commonCellStyle;



                var rowTemp13 = rowTemp.CreateCell(13);
                rowTemp13.SetCellValue(listModel[i].status.ToString());
                rowTemp13.CellStyle = commonCellStyle;



                var rowTemp14 = rowTemp.CreateCell(14);
                rowTemp14.SetCellValue(listModel[i].parentId.ToString());
                rowTemp14.CellStyle = commonCellStyle;



                var rowTemp15 = rowTemp.CreateCell(15);
                rowTemp15.SetCellValue(listModel[i].userWx.ToString());
                rowTemp15.CellStyle = commonCellStyle;



                var rowTemp16 = rowTemp.CreateCell(16);
                rowTemp16.SetCellValue(listModel[i].isDelete.ToString());
                rowTemp16.CellStyle = commonCellStyle;


            }
            // 写入到excel
            string webRootPath = _webHostEnvironment.WebRootPath;
            string tpath = "/files/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-CoreCmsUser导出(查询结果).xls";
            string filePath = webRootPath + tpath;
            DirectoryInfo di = new DirectoryInfo(filePath);
            if (!di.Exists)
            {
                di.Create();
            }
            FileStream fileHssf = new FileStream(filePath + fileName, FileMode.Create);
            book.Write(fileHssf);
            fileHssf.Close();

            jm.code = 0;
            jm.msg = GlobalConstVars.ExcelExportSuccess;
            jm.data = tpath + fileName;

            return jm;
        }
        #endregion

        #region 修改余额============================================================

        // POST: Api/CoreCmsUser/GetEditBalance
        /// <summary>
        ///     修改余额
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("修改余额")]
        public async Task<AdminUiCallBack> GetEditBalance([FromBody] FMIntId entity)
        {
            //返回数据
            var jm = new AdminUiCallBack();

            var model = await _coreCmsUserServices.QueryByIdAsync(entity.id);
            if (model == null)
            {
                jm.msg = "不存在此信息";
                return jm;
            }

            jm.code = 0;
            jm.data = model;

            return jm;
        }

        #endregion

        #region 修改余额提交============================================================

        // POST: Api/CoreCmsUser/DoEditBalance
        /// <summary>
        ///     修改余额提交
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("修改余额提交")]
        public async Task<AdminUiCallBack> DoEditBalance([FromBody] FMUpdateUserBalance entity)
        {
            var jm = await _coreCmsUserServices.UpdateBalance(entity.id, entity.balance, entity.memo);
            return jm;
        }

        #endregion

        #region 修改积分============================================================

        // POST: Api/CoreCmsUser/GetEditPoint
        /// <summary>
        ///     修改积分
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("修改积分")]
        public async Task<AdminUiCallBack> GetEditPoint([FromBody] FMIntId entity)
        {
            //返回数据
            var jm = new AdminUiCallBack();

            var model = await _coreCmsUserServices.QueryByIdAsync(entity.id);
            if (model == null)
            {
                jm.msg = "不存在此信息";
                return jm;
            }

            jm.code = 0;
            jm.data = model;

            return jm;
        }

        #endregion

        #region 修改积分提交============================================================

        // POST: Api/CoreCmsUser/DoEditPoint
        /// <summary>
        ///     修改积分提交
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("修改积分提交")]
        public async Task<AdminUiCallBack> DoEditPoint([FromBody] FMUpdateUserPoint entity)
        {
            var jm = await _coreCmsUserServices.UpdatePiont(entity);
            return jm;
        }

        #endregion

        #region 修改上级推荐人============================================================

        // POST: Api/CoreCmsUser/GetEditParentId
        /// <summary>
        ///     修改上级推荐人
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("修改上级推荐人")]
        public async Task<AdminUiCallBack> GetEditParentId([FromBody] FMIntId entity)
        {
            //返回数据
            var jm = new AdminUiCallBack();

            var model = await _coreCmsUserServices.QueryByIdAsync(entity.id);
            if (model == null)
            {
                jm.msg = "不存在此信息";
                return jm;
            }

            var parentName = string.Empty;
            if (model.parentId > 0)
            {
                var parent = await _coreCmsUserServices.QueryByClauseAsync(p => p.id == model.parentId);
                if (parent != null)
                {
                    parentName = parent.nickName;
                }
            }

            jm.code = 0;
            jm.data = new
            {
                model,
                parentName
            };

            return jm;
        }

        #endregion

        #region 修改上级推荐人提交============================================================

        // POST: Api/CoreCmsUser/DoEditPoint
        /// <summary>
        ///     修改上级推荐人提交
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("修改上级推荐人提交")]
        public async Task<AdminUiCallBack> DoEditParentId([FromBody] FMUpdateUserParentId entity)
        {
            var jm = new AdminUiCallBack();

            if (entity.id == entity.parentId)
            {
                jm.msg = "禁止设置自己为自己的推荐人";
                return jm;
            }

            var model = await _coreCmsUserServices.QueryByIdAsync(entity.id);
            if (model == null)
            {
                jm.msg = "不存在此信息";
                return jm;
            }

            if (entity.parentId > 0)
            {
                var parentObj = await _coreCmsUserServices.QueryByIdAsync(entity.parentId);
                if (parentObj == null)
                {
                    jm.msg = "不存在此上级信息";
                    return jm;
                }

                if (parentObj.parentId == model.id)
                {
                    jm.msg = "不允许双方互相设置为上级";
                    return jm;
                }
            }
            else
            {
                entity.parentId = 0;
            }

            var bl = await _coreCmsUserServices.UpdateAsync(p => new CoreCmsUser() { parentId = entity.parentId }, p => p.id == model.id);

            jm.code = bl ? 0 : 1;
            jm.msg = bl ? "更新成功" : "更新失败";
            return jm;
        }

        #endregion

        #region 余额详情列表============================================================

        // POST: Api/CoreCmsUser/GetUserBalancePageList
        /// <summary>
        ///     余额详情列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("余额详情列表")]
        public async Task<AdminUiCallBack> GetUserBalancePageList()
        {
            var jm = new AdminUiCallBack();
            var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
            var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
            var where = PredicateBuilder.True<CoreCmsUserBalance>();
            //获取排序字段
            var orderField = Request.Form["orderField"].FirstOrDefault();
            Expression<Func<CoreCmsUserBalance, object>> orderEx;
            switch (orderField)
            {
                case "id":
                    orderEx = p => p.id;
                    break;
                case "userId":
                    orderEx = p => p.userId;
                    break;
                case "type":
                    orderEx = p => p.type;
                    break;
                case "money":
                    orderEx = p => p.money;
                    break;
                case "balance":
                    orderEx = p => p.balance;
                    break;
                case "sourceId":
                    orderEx = p => p.sourceId;
                    break;
                case "memo":
                    orderEx = p => p.memo;
                    break;
                case "createTime":
                    orderEx = p => p.createTime;
                    break;
                default:
                    orderEx = p => p.id;
                    break;
            }

            //设置排序方式
            var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
            var orderBy = orderDirection switch
            {
                "asc" => OrderByType.Asc,
                "desc" => OrderByType.Desc,
                _ => OrderByType.Desc
            };
            //查询筛选

            //序列 int
            var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
            if (id > 0) where = where.And(p => p.id == id);
            //用户id int
            var userId = Request.Form["userId"].FirstOrDefault().ObjectToInt(0);
            if (userId > 0) where = where.And(p => p.userId == userId);
            //类型 int
            var type = Request.Form["type"].FirstOrDefault().ObjectToInt(0);
            if (type > 0) where = where.And(p => p.type == type);
            //资源id nvarchar
            var sourceId = Request.Form["sourceId"].FirstOrDefault();
            if (!string.IsNullOrEmpty(sourceId)) where = where.And(p => p.sourceId.Contains(sourceId));
            //描述 nvarchar
            var memo = Request.Form["memo"].FirstOrDefault();
            if (!string.IsNullOrEmpty(memo)) where = where.And(p => p.memo.Contains(memo));
            //创建时间 datetime
            var createTime = Request.Form["createTime"].FirstOrDefault();
            if (!string.IsNullOrEmpty(createTime))
            {
                if (createTime.Contains("到"))
                {
                    var dts = createTime.Split("到");
                    var dtStart = dts[0].Trim().ObjectToDate();
                    where = where.And(p => p.createTime > dtStart);
                    var dtEnd = dts[1].Trim().ObjectToDate();
                    where = where.And(p => p.createTime < dtEnd);
                }
                else
                {
                    var dt = createTime.ObjectToDate();
                    where = where.And(p => p.createTime > dt);
                }
            }

            //获取数据
            var list = await _coreCmsUserBalanceServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize);
            //返回数据
            jm.data = list;
            jm.code = 0;
            jm.count = list.TotalCount;
            jm.msg = "数据调用成功!";
            return jm;
        }

        #endregion

        #region 余额详情============================================================

        // POST: Api/CoreCmsUser/GetDetailsBalanceLog
        /// <summary>
        ///     余额详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("余额详情")]
        public AdminUiCallBack GetDetailsBalanceLog()
        {
            //返回数据
            var jm = new AdminUiCallBack { code = 0 };

            var userBalanceSourceTypes = EnumHelper.EnumToList<GlobalEnumVars.UserBalanceSourceTypes>();
            jm.data = new
            {
                userBalanceSourceTypes
            };
            return jm;
        }

        #endregion

        #region 获取积分列表============================================================

        // POST: Api/CoreCmsUser/GetUserPointLogPageList
        /// <summary>
        ///     获取积分列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("获取积分列表")]
        public async Task<AdminUiCallBack> GetUserPointLogPageList()
        {
            var jm = new AdminUiCallBack();
            var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
            var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
            var where = PredicateBuilder.True<CoreCmsUserPointLog>();
            //获取排序字段
            var orderField = Request.Form["orderField"].FirstOrDefault();
            Expression<Func<CoreCmsUserPointLog, object>> orderEx;
            switch (orderField)
            {
                case "id":
                    orderEx = p => p.id;
                    break;
                case "userId":
                    orderEx = p => p.userId;
                    break;
                case "type":
                    orderEx = p => p.type;
                    break;
                case "num":
                    orderEx = p => p.num;
                    break;
                case "balance":
                    orderEx = p => p.balance;
                    break;
                case "remarks":
                    orderEx = p => p.remarks;
                    break;
                case "createTime":
                    orderEx = p => p.createTime;
                    break;
                default:
                    orderEx = p => p.id;
                    break;
            }

            //设置排序方式
            var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
            var orderBy = orderDirection switch
            {
                "asc" => OrderByType.Asc,
                "desc" => OrderByType.Desc,
                _ => OrderByType.Desc
            };
            //查询筛选

            //ID int
            var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
            if (id > 0) where = where.And(p => p.id == id);
            //用户ID int
            var userId = Request.Form["userId"].FirstOrDefault().ObjectToInt(0);
            if (userId > 0) where = where.And(p => p.userId == userId);
            //类型 int
            var type = Request.Form["type"].FirstOrDefault().ObjectToInt(0);
            if (type > 0) where = where.And(p => p.type == type);
            //积分数量 int
            var num = Request.Form["num"].FirstOrDefault().ObjectToInt(0);
            if (num > 0) where = where.And(p => p.num == num);
            //积分余额 int
            var balance = Request.Form["balance"].FirstOrDefault().ObjectToInt(0);
            if (balance > 0) where = where.And(p => p.balance == balance);
            //备注 nvarchar
            var remarks = Request.Form["remarks"].FirstOrDefault();
            if (!string.IsNullOrEmpty(remarks)) where = where.And(p => p.remarks.Contains(remarks));
            //创建时间 datetime
            var createTime = Request.Form["createTime"].FirstOrDefault();
            if (!string.IsNullOrEmpty(createTime))
            {
                if (createTime.Contains("到"))
                {
                    var dts = createTime.Split("到");
                    var dtStart = dts[0].Trim().ObjectToDate();
                    where = where.And(p => p.createTime > dtStart);
                    var dtEnd = dts[1].Trim().ObjectToDate();
                    where = where.And(p => p.createTime < dtEnd);
                }
                else
                {
                    var dt = createTime.ObjectToDate();
                    where = where.And(p => p.createTime > dt);
                }
            }

            //积分余额 int
            var searchType = Request.Form["searchType"].FirstOrDefault();
            if (!string.IsNullOrEmpty(searchType) && searchType == "accumulativePoint")
            {
                where = where.And(p => p.num > 0);
            }


            //获取数据
            var list = await _coreCmsUserPointLogServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent,
                pageSize);
            //返回数据
            jm.data = list;
            jm.code = 0;
            jm.count = list.TotalCount;
            jm.msg = "数据调用成功!";
            return jm;
        }

        #endregion

        #region 积分详情============================================================

        // POST: Api/CoreCmsUser/GetDetailsPointLog
        /// <summary>
        ///     积分详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("余额详情")]
        public AdminUiCallBack GetDetailsPointLog()
        {
            //返回数据
            var jm = new AdminUiCallBack { code = 0 };
            var userPointSourceTypes = EnumHelper.EnumToList<GlobalEnumVars.UserPointSourceTypes>();
            jm.data = new
            {
                userPointSourceTypes
            };
            return jm;
        }

        #endregion

        #region 设置删除标志============================================================

        // POST: Api/CoreCmsUser/DoSetisDelete/10
        /// <summary>
        ///     设置删除标志 有数据就是删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("设置删除标志")]
        public async Task<AdminUiCallBack> DoSetisDelete([FromBody] FMUpdateBoolDataByIntId entity)
        {
            var jm = new AdminUiCallBack();

            var oldModel = await _coreCmsUserServices.QueryByIdAsync(entity.id);
            if (oldModel == null)
            {
                jm.msg = "不存在此信息";
                return jm;
            }

            oldModel.isDelete = entity.data;

            var bl = await _coreCmsUserServices.UpdateAsync(oldModel);
            jm.code = bl ? 0 : 1;
            jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;

            return jm;
        }

        #endregion
    }
}